package com.easyjob.controller;

import com.easyjob.annotation.GlobalInterceptor;
import com.easyjob.annotation.VerifyParam;
import com.easyjob.entity.enums.PermissionCodeEnum;
import com.easyjob.entity.po.QuestionBank;
import com.easyjob.entity.query.QuestionBankQuery;
import com.easyjob.entity.vo.ResponseVO;
import com.easyjob.service.QuestionBankService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/bankList")
public class QuestionBankController extends ABaseController{

    @Resource
    private QuestionBankService questionBankService;

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/loadAllBank")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_LIST)
    public ResponseVO loadDataList(QuestionBankQuery query) {
        query.setOrderBy("sort asc");
        return getSuccessResponseVO(questionBankService.findListByParam(query));
    }

    @RequestMapping("/saveBank")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_EDIT)
    public ResponseVO saveCategory(QuestionBank questionBank) {
        questionBankService.saveQuestionBank(questionBank);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/delBank")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_EDIT)
    public ResponseVO delCategory(@VerifyParam(required = true) Integer bankId) {
        questionBankService.deleteQuestionBankByBankId(bankId);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/changeSort")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_EDIT)
    public ResponseVO changeSort(@VerifyParam(required = true) String bankIds) {
        questionBankService.changeSort(bankIds);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/loadAllBank4Select")
    @GlobalInterceptor
    public ResponseVO loadAllCategory(Integer type) {
        return getSuccessResponseVO(questionBankService.loadAllCategoryByType(type));
    }
}
